package com.cf.game.cowboy.handler;

import com.cf.game.cowboy.MessageHandler;
import com.cf.serialize.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * cf-game-HandlerContext
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/3/27 14:29
 */
@Component
public class HandlerContext {

    @Autowired
    private List<MessageHandler> handlerList;

    /**
     * 获取合适的处理器
     *
     * @param message
     * @return
     */
    public MessageHandler getSuitableMessageHandler(Message message) {
        if (message == null)
            return null;
        for (MessageHandler messageHandler : handlerList) {
            if (messageHandler.support(message.getClass())) {
                return messageHandler;
            }
        }
        return null;
    }

}
